/**
 * LdSmsTask.java 
 * Copyright © 2009-2014, Liu Tao
 * 
 * @author Liu Tao
 * @create 2014年5月19日
 */
package com.pshare.msg.sms.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.pshare.msg.sms.service.SmsTask;
import com.pshare.util.HttpUtils;
import com.pshare.util.RandomCodeUtils;
import com.pshare.util.SysPropertyUtils;

/**
 * 联合维拓短信接口
 */
public class LdSmsTask extends SmsTask {
	
	private static final Logger logger = Logger.getLogger(LdSmsTask.class);
	
	private static final String URL = "http://sdk.univetro.com.cn:6200/sdkproxy/sendsms.action";
	private static final String cdkey = SysPropertyUtils.getProperty("sms.cdkey");
	private static final String password = SysPropertyUtils.getProperty("sms.pwd");
	private static final String SIGNATURE = "【" + SysPropertyUtils.getProperty("sms.signature") + "】";
	
	private static Map<String, String> params = new HashMap<String, String>();
	
	private String cellphone;
	private String message;
	
	static {
		params.put("action", "send");
		params.put("cdkey", cdkey);
		params.put("password", password);
	}
	
	public LdSmsTask() {
		
	}
	
	public LdSmsTask(String cellphone, String message) {
		this.cellphone = cellphone;
		this.message = message;
	}

	@Override
	public void sendMsg() {
		Map<String, String> p = new HashMap<String, String>();
		p.putAll(params);
		// 短信核实的唯一标识，这里用不着，随便写一个
		p.put("seqid", cellphone + RandomCodeUtils.getRandomNum(5));
		p.put("phone", cellphone);
		p.put("message", SIGNATURE + message);
		try {
			HttpUtils.urlGet(URL, p);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

}
